<?php
class Catalog_Controller extends MY_Controller{
	protected $_controller_path = '/catalog/Catalog_Controller';
	protected $_list_path = '/catalog/list';
	protected $_model = 'catalog/Catalog_Model';
	protected $_view_path = 'catalog/view';
	protected $_create_path = 'catalog/create';
	protected $_edit_path = 'catalog/edit';
	protected $_sort_id_type = 'DESC';
	protected $_resource_id = self::CATALOG_RESOURCE;
	
	
	function __construct() {
		parent::__construct();
		$this->model = new Catalog();
	}
	
	protected function setFormValidation() {
		$this->form_validation->set_rules('catalog_name','Catalog name','trim|required');
	}
	
	protected function init_input_data() {
		$catalog_name = $this -> input -> post('catalog_name');
		$sort_id= $this -> input -> post('sort_id');
		$meta_data = unsign($catalog_name);
		return array(
			'catalog_name' => $catalog_name,
			'sort_id' => $sort_id,
			'meta_data' => $meta_data,
		);
	}
	
	protected function save_new_object() {
		$catalog = new Catalog();
		$catalog -> catalog_name = $this -> input -> post('catalog_name');
		$catalog -> sort_id= $this -> input -> post('sort_id');
		$catalog -> meta_data = unsign($catalog -> catalog_name);
		$catalog->save_as_new();
	}
	
	protected function init_quick_input_data($id) {
		$catalog_name = $this -> input -> post('catalog_name'.$id);
		$sort_id= $this -> input -> post('sort_id'.$id);
		$meta_data = unsign($catalog_name);
		return array(
			'catalog_name' => $catalog_name,
			'sort_id' => $sort_id,
			'meta_data' => $meta_data,
		);
	}
	
	protected function setQuickEditFormValidation($id) {
		$this -> form_validation -> set_rules('catalog_name'.$id, 'Catalog name', 'trim|required');
		$this -> form_validation -> set_rules('sort_id'.$id, 'Sort id', 'is_natural');
	}
	
	protected function update_object($id) {
		$catalog = new Catalog();
		$catalog->where('id', $id)->get();
		$catalog -> catalog_name = $this -> input -> post('catalog_name'.$id);
		$catalog -> sort_id= $this -> input -> post('sort_id'.$id);
		$catalog -> meta_data = unsign($catalog -> catalog_name);
		$catalog->save();
	}
	
	protected function quick_update_object($id) {
		$this->update_object($id);
	}
	
	public static function register_resource() {
		$resource = array(
			'id' => 2,
			'name' => 'Catalog',
			'description' =>''
		);
	}
}
?>